<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateArticleAccessTable extends Migrator
{
    public function up()
    {
        // 创建oa_article_access表
        $table = $this->table('oa_article_access');
        $table->addColumn('article_id', 'integer', [
            'limit' => 11,
            'default' => 0,
            'comment' => '文章ID'
        ])
        ->addColumn('user_id', 'integer', [
            'limit' => 11,
            'default' => 0,
            'comment' => '用户ID'
        ])
        ->addColumn('department_id', 'integer', [
            'limit' => 11,
            'default' => 0,
            'comment' => '部门ID'
        ])
        ->addColumn('type', 'integer', [
            'limit' => 1,
            'default' => 1,
            'comment' => '类型:1用户,2部门'
        ])
        ->addColumn('create_time', 'bigint', [
            'limit' => 11,
            'default' => 0,
            'comment' => '创建时间'
        ])
        ->addIndex(['article_id'])
        ->addIndex(['user_id'])
        ->addIndex(['department_id'])
        ->addIndex(['type'])
        ->create();
    }

    public function down()
    {
        // 删除oa_article_access表
        $this->table('oa_article_access')->drop();
    }
}